#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <iostream>

using namespace std;

int main()
{
    const char *pathname = "/home/zh";
    int proj_id = 12;
    int size = 4096;

    key_t key = ftok(pathname, proj_id);
    if (key < 0)
    {
        perror("ftok");
        return -1;
    }
    cout << "key值被成功创建,key:" << key << endl;

    int shmid = shmget(key, size, IPC_CREAT | IPC_EXCL);
    if (shmid < 0)
    {
        perror("shmget");
        return -1;
    }
    cout<<"共享内存标识码被成功创建，shmid:"<<shmid<<endl;
    return 0;
}